package com.seven.monior;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;


import com.seven.monior.AppInfo.AppInfo;
import com.seven.monior.AppInfo.Global;

public class AppDetail extends Activity {
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        Intent intent=this.getIntent();
//        Bundle bundle=intent.getExtras();
//        AppInfo appInfo=(AppInfo)bundle.getSerializable("appinfo");
//        
//        Log.e("APP DETAIL", appInfo.AppInfoDetail());
        
        setContentView(R.layout.apps_item_detail);
        showAppInfoDetail(Global.appInfo);
               
        
    }
	
	private void showAppInfoDetail(AppInfo appInfo){
		TextView tvAppName=(TextView)findViewById(R.id.appName_detail);
		TextView tvAppVersion=(TextView)findViewById(R.id.appVersion_detail);
		ImageView ivAppIcon=(ImageView)findViewById(R.id.appIcon_detail);
		ListView lvAppPermissions=(ListView)findViewById(R.id.appPermissions);
		
		tvAppName.setText(appInfo.getAppName());
		tvAppVersion.setText(appInfo.getVersionName());
		ivAppIcon.setImageDrawable(appInfo.getIcon());
		
		

		
		List<Map<String, Object>> data=getData(Global.appInfo);
		SimpleAdapter permissionAdapter = new SimpleAdapter(this, data, R.layout.permissions_list_item, 
				new String[]{"appPermissionTitle","appPermissionContent"}, 
				new int[]{R.id.appPermission_detail_title,R.id.appPermission_detail_content});
		lvAppPermissions.setAdapter(permissionAdapter);
	}
	
	private List<Map<String, Object>> getData(AppInfo appInfo) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		ArrayList<String> permission = appInfo.getPermissions();
		for (int i = 0; i < permission.size(); i++) {
			String strPermission = permission.get(i);
			Map<String, Object> map = new HashMap<String, Object>();

			map.put("appPermissionTitle", strPermission);
			map.put("appPermissionContent", strPermission);
			list.add(map);
		}

		return list;

	}

}
